package org.spitter.web.controller;

import java.util.HashMap;
import java.util.Map;

import javax.inject.Inject;

import org.spitter.core.service.SpittleService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * Handles requests for the application home page.
 */
@Controller
public class HomeController {
	public static final int DEFAULT_SPITTLES_PER_PAGE = 25;

	private SpittleService spittleService;

	@Inject
	public HomeController(SpittleService spittleService) {
		this.spittleService = spittleService;
	}

	@RequestMapping({ "/", "/home" })
	public String showHomePage(Map<String, Object> model) {
		model.put("spittles",
				spittleService.getRecentSpittles(DEFAULT_SPITTLES_PER_PAGE));
		return "home";
	}
}
